package cc.willrock.algorithm.sort;

import java.util.Arrays;

public class BubbleSort {
	public static int [] sort(int[] a){
		for(int j = a.length-1;j>0;j--){
			for(int i  = 0;i<j;i++){
				
				int temp=0;
				if(a[i]>a[i+1]){
					//swap
					temp = a[i];
					a[i]=a[i+1];
					a[i+1] = temp;
				}
			}
		}
				
		return a;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] a = {15,9,8,1,4,11,7,12,13,6,5,3,16,2,10,14};
		//int[] a = { 5, 3, 1, 2, 4 };
		System.out.println(Arrays.toString(a));
		System.out.println(Arrays.toString(sort(a)));

	}

}
